import Vue from 'vue';
import Vuex from "vuex"

Vue.use(Vuex)

const store = new Vuex.Store({
	state:{
		historyList: uni.getStorageSync('__history') || [],
		user_id:"60c2d733f6a3980001d73348",
		userinfo:{},
	},
	mutations:{
		SET_USER_ID(state, user_id){
			state.user_id = user_id
		},
		SET_USERINFOR(state, userinfo){
			state.userinfo = userinfo
		},
		SET_HISTORY_LIST(state, history){
			state.historyList = history
		},
		CLEAR_HISTORY(state, history){
			state.historyList = []
		}
	},
	actions:{
		set_history({commit, state},history){
			let list = state.historyList
			if (list.indexOf(history) > -1) {
				list.splice(list.indexOf(history), 1) 
			}
			list.unshift(history)
			uni.setStorageSync('__history',list)
			commit("SET_HISTORY_LIST", list)
		},
		clearHistory({commit, state},history){
			// uni.setStorageSync('__history',[])
			uni.removeStorageSync('__history')
			commit("CLEAR_HISTORY")
		}
	}
})

export  default store